<html>
<head>
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<img style="margin-left:42%; text-align:center" src="./img/logo_txt_only.jpg" />
<div style="text-align:center;background-color:#d0ddcf;border: 1px solid #9CAA9C;width:300px;margin-left:40%;margin-left:40%;">


<?php

include('functions.php');

dbConnect();

if(isset($_POST['postItem']) && isLi()){
	
	
	$i = $_POST['name'];
	$p = $_POST['price'];
	$de = $_POST['description'];
	$u = $_POST['user'];
	$d = $_POST['domain'];
	$image = 0;
	
	
	if ($_FILES["image"]["error"] > 0)
	  {
		echo "Your image could not be uploaded";
	    echo "Error: " . $_FILES["image"]["error"] . "<br />";
		$image = 0;
	  }
	$allowedExts = array("jpg", "jpeg", "gif", "png");
	$extension = end(explode(".", $_FILES["image"]["name"]));
	
	if ((($_FILES["image"]["type"] == "image/gif")
	|| ($_FILES["image"]["type"] == "image/jpeg")
	|| ($_FILES["image"]["type"] == "image/jpeg"))
	&& ($_FILES["image"]["size"] < 20000)
	&& in_array($extension, $allowedExts))
	  {
	  if ($_FILES["image"]["error"] > 0)
	    {
	    echo "Return Code: " . $_FILES["image"]["error"] . "<br />";
		echo 'wont work';
	    }
	  else
	    {
	    echo "Upload: " . $_FILES["image"]["name"] . "<br />";
	    echo "Type: " . $_FILES["image"]["type"] . "<br />";
	    echo "Size: " . ($_FILES["image"]["size"] / 1024) . " Kb<br />";
	    echo "Temp file: " . $_FILES["image"]["tmp_name"] . "<br />";

		
		$sql = mysql_query("INSERT INTO posts (item, description, username, domain, price, hits, views, created, modified, img) VALUES ('$i', '$de', '$u', '$d', '$p', '0', '0', NOW(), NOW(), '$image')");
		
		$sql2 = "SELECT id FROM posts WHERE item = '$i'";
		$idQuery = mysql_fetch_array($sql2);
		$fileId = $idQuery[0];
		
		  move_uploaded_file($_FILES["file"]["tmp_name"],
	      "uploads/" . $_FILES["file"][$fileId]);
	      echo "Stored in: " . "uploads/" . $_FILES["file"][$fileId];
	    }
	  }

	echo 'Item Posted';
} else {
	$ip = $_SERVER['REMOTE_ADDR'];
	echo 'You do not have permission to be on this page, your IP has been logged';
	logAction($ip, 'unauthorized access to the postItem.php page');
}


?>

</div>

<a style="margin-left:48%;text-align:center;color:black" href="<?= getUrl(); ?>">Return Home</a>

</html>